Tomáš Pospíšek's Notizblock

a little standard for shell scripts

Scripts are like code - after a while you forget them.

A --help switch comes in handy then. So it'd be nice to have that...

$ vimxb --help
usage: vimx [params] file

    create and edit executable bash script under ~/bin

ah, nice, so let's do that:

$ vimxb unawsomize

and poof we're inside vim and...

#!/bin/bash

help() {
   echo 'usage: unawsomize'
   echo '       unawsomize --help'
   echo
   exit 1
}

[ "$1" == "--help" ] && help

You only need to add the code and document it inside "help()":

#!/bin/bash

help() {
   echo 'usage: unawsomize file'
   echo '       unawsomize --help'
   echo
   echo "    unawsomize let's you reduce the awsomeness"
   echo '    onslaught level in files.'
   exit 1
}

[ "$1" == "--help" ] && help

sed --in-place 's/awsome//g' "$1"

Now you save and finaly you can get rid of too much awesome:

$ unawsomize ~/bin/unawsomize

oops...

$ vimxb unawsomize
#!/bin/bash

help() {
   echo 'usage: unawsomize'
   echo '       unawsomize --help'
   echo "    unawsomize let's you reduce the ness"
   echo '    onslaught level in files.'
   echo
   exit 1
}

[ "$1" == "--help" ] && help

sed --in-place 's///g' "$1"

No wonder that didn't work...

vimxb can be found in the little_shell_scripts repository. You'll also need vimx which vimxb depends on.

Tomáš Pospíšek, 2015-09-17

Articles